<?php
/**
 * Created By Project
 * Author: 陈东
 * Copyright：陈东
 * Source Code：陈东
 * Explain：I shall not authorize for any other commercial purposes, law breakers must be prosecuted.
 */
namespace Admin\Controller;
use Think\Controller;

class FiltrateController extends BaseController {

	//读取文本
	public function index(){
		$path = './10000.txt';
		$file = fopen($path, "r");
		$content = array();
		$i=0;
		while(!feof($file)){
			$content[$i]= trim(fgets($file));
			$i++;
		}
		fclose($file);
		$dataarray = array_filter($content);

//		foreach($dataarray as $key=>$v){
//			$vdata = trim($v);
//			if(!empty($vdata)){
//				echo $key.'、'.$this->showdata($vdata).'<br>';
//			}
//		}

		echo "已屏蔽 ".$this->showdata($dataarray)." 条数据";
		echo "一等奖微信红包18元：".$this->showdata($dataarray,51);
		echo "二等奖微信红包8.8元：".$this->showdata($dataarray,52);
		echo "三等奖微信红包1.8元：".$this->showdata($dataarray,53);
		echo "特等奖：".$this->showdata($dataarray,54);
		echo "华人钻：".$this->showdata($dataarray,1);

	}

	protected function showdata($vdata,$awardid=null){
		$field = 'id,ma_randnumber,ma_hb_cishu,ma_type';
		$randnumber = D(C('TABLE_RANDNUMBER'));
		$where['ma_randnumber'] = array('in',$vdata);
		$where['ma_rootid'] = 275;
		$where['ma_hb_cishu'] = 0;
		if(!empty($awardid)) $where['ma_type'] = $awardid;
			$res = $randnumber->field($field)->where($where)->select();
			if(!empty($awardid)){
				$sum = count($res);
				$money = $this->money($awardid);
				$arr = array('51','52','53');
				return in_array($awardid,$arr) ? $sum.' * '.$money.' = '.$sum*$money."<br>" : $sum."<br>";
			}else{
				$randnumber1 = D(C('TABLE_RANDNUMBER'));
				$data['isvalid'] = 0;
				$data['ma_hb_cishu'] = 1;
				$res = $randnumber1->where($where)->save($data);
				if($res){
					return $res."<br>";
				}
//			if($res){
//				foreach($res as $key=>$v){
//					echo $key.'、'.$v['id'].'->'.$v['ma_randnumber'].'->'.$v['ma_hb_cishu'].'->'.$v['ma_type'].'<br>';
//				}
//
//			}
		}
	}

	//钱统计
	protected function money($awardid){
		switch ($awardid){
			case 51:
				return 18;
				break;
			case 52:
				return 8.8;
				break;
			case 53:
				return 1.8;
				break;
			default:
				return 1;
		}
	}


//	protected function showdata($vdata){
//		$randnumber = D(C('TABLE_RANDNUMBER'));
//		$res = $randnumber->field('id,ma_randnumber,ma_hb_cishu,ma_type')->where(array('ma_randnumber'=>$vdata,'ma_rootid'=>275))->find();
//		if($res){
//			return $res['id'].'->'.$res['ma_randnumber'].'->'.$res['ma_hb_cishu'].'->'.$res['ma_type'].'<br>';
//		}
//	}


}